<template>
	<view class="evaluate p-3">
		<LeftRight :data="evalutateList" @ToDetail="getItemInfo">
			<template #bottom="{item}">
				<view v-if="(getEvaluateDay(item.endTime) +　3) > 0 " class="buttom flex justify-between pl-1 pr-1 font-sm align-center">
					<view>距离评价截至还剩<text style="color: red;">{{getEvaluateDay(item.endTime) +　3}}天</text></view>
					<view>
						<view class="btn" @click="goDetail">评价</view>
					</view>
				</view>
				
				<view v-else class="buttom flex justify-between pl-1 pr-1 font-sm align-center">
					<view class="text-shallow">该评价时间已过期</view>
					<view>
						<view class="btn disabled text-shallow" >评价</view>
					</view>
				</view>
			</template>
		</LeftRight>
	</view>
</template>
<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		onShow
	} from "@dcloudio/uni-app"
	import LeftRight from '../../component/commonLayout/LeftRight.vue';
	import request from '../../api/index.js'
	

	const evalutateList = ref([])
	const itemId = ref(0)
	
	

	const getEvaluateDay = (endTime) => {

		const now = new Date();
		const end = new Date(endTime);
		const remainingTimeMs = end.getTime() - now.getTime();
		const remainingDays = Math.ceil(remainingTimeMs / (1000 * 60 * 60 * 24)) ;
		console.log(`距离评价截止还剩 ${remainingDays} 天`);
		return remainingDays
		
	};

	const goDetail = () => {
		setTimeout(() => {
			uni.navigateTo({
				url: `/pages/submitEvalate/submitEvalate?data=${itemId.value}`
			})
		}, 20)

	}

	const getItemInfo = (item) => {
		console.log("item--------", item.id);
		itemId.value = item.id
		console.log("itemId.value--------", itemId.value);
	}
	const gitEvalutateList = (status) => {
		request({
			url: '/api/volunteer/activity/SelectActivityByUser',
			method: 'GET',
			data: {
				status: status,

			}
		}, e => {
			if (e.success) {
				console.log('e-------------', e.data.records)
				evalutateList.value = e.data.records
				evalutateList.value.forEach((item) => {
					item.responsibleimg = JSON.parse(item.responsibleimg)
					console.log('item.responsibleimg-------------', item.responsibleimg)
				})

			} else {
				uni.showToast({
					title: '获取请假列表信息失败',
					icon: 'none'
				})
			}
		})
	}
	
	onShow(()=>{
		gitEvalutateList(6); //6 为评价活动列表
	})

	onMounted(() => {
		
	})
</script>

<style lang="scss" scoped>
	.evaluate {
		margin-top: -20rpx;

		.btn {
			padding: 10rpx 30rpx;
			border: 1rpx solid #ccc;
			border-radius: 50rpx;

		}
	}
</style>